package com.unisound.tracelog.server.exception;

import com.unisound.tracelog.common.exception.BusinessException;
import com.unisound.tracelog.common.model.dto.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
@ControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = Throwable.class)
    public ResultDTO throwableHandler(Throwable e) {
        log.error("throwableHandler", e);
        return ResultDTO.fail("10000", "系统错误");
    }

    @ExceptionHandler(value = BusinessException.class)
    public ResultDTO businessExceptionHandler(BusinessException e) {
        log.error("businessExceptionHandler", e);
        return ResultDTO.fail("10001", e.getMessage());
    }

}
